package com.yan_jiu_sheng.LeetCodeHot100.AC;

/**
 * https://leetcode.cn/problems/reverse-linked-list/?envType=study-plan-v2&envId=top-100-liked
 * 通过
 *
 * @author yulongTian
 * @create 2024-05-29 14:59
 */
public class Test23 {
    public static void main(String[] args) {

    }

    private class ListNode {
        int val;
        ListNode next;

        ListNode(int x) {
            val = x;
            next = null;
        }
    }

    public ListNode reverseList(ListNode head) {
        if (head == null || head.next == null) {
            return head;
        }
        ListNode resHead = head;
        head = head.next;
        resHead.next = null;
        while (head != null) {
            ListNode temp = head;
            head = head.next;

            temp.next = resHead;
            resHead = temp;
        }
        return resHead;
    }


}
